package com.example.voting_master.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.voting_master.entity.Candidate;
import com.example.voting_master.entity.CandidateVoteStats;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CandidateVoteStatsMapper extends BaseMapper<CandidateVoteStats> {

    @Select("SELECT cvs.id,cvs.candidate_id,cvs.theme_id,COUNT(uvl.candidate_id and uvl.theme_id) as votes " +
            "FROM candidate_vote_stats as cvs, user_vote_log as uvl " +
            "WHERE cvs.candidate_id = uvl.candidate_id and cvs.theme_id = uvl.theme_id " +
            "GROUP BY cvs.id")
    List<CandidateVoteStats> selectCandidatesVotes();
}
